<?php
namespace App\Http\Controllers\Wxxcx;

use App\Services\Wxxcx\ScanService;
use Illuminate\Http\Request;

class ScanController extends  BaseController
{
    /** p
     * 二维码
     */

    protected $db;

    public function __construct(ScanService $service)
    {
        $this->db = $service;
    }

    //看看码有没有
    public function isExist(Request $request)
    {
        $code = $request->post('code', '');
        if (!$code) {
            return $this->toJson(-2, '缺少参数');
        }
        $res = $this->db->isExist($code);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }

    //查编号
    public function getOneBySerial(Request $request)
    {
        $showCode = $request->post('show_code', '');
        if (!$showCode) {
            return $this->toJson(-2, '缺少参数');
        }
        $res = $this->db->getOneBySerial($showCode);
        if ($res['code'] != 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }
}